package com.fyi.springbootmongocomment.controller;

import com.fyi.springbootmongocomment.pojo.Comment;
import com.fyi.springbootmongocomment.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Map;

@RestController
public class CommentController {




    @Autowired
    private CommentService commentService;
    @DeleteMapping("/com")
    public long del(String _id){
        long del = commentService.del(_id);
        return del;
    }

    @PostMapping("/com")
    public Integer add(Comment comment){
        System.out.println(comment.getContent());
        List<Comment> select = commentService.selectAll();
        Integer i = select.size() + 1;
        String _id = String.valueOf(i);
        comment.set_id(_id);
        comment.setArticleid("100001");
        comment.setUserid("1008");
        comment.setNickname("ljz");
        comment.setCreatedatetime(new Date());
        comment.setLikenum(0);
        comment.setReplynum(0);
        comment.setState("1");
        comment.setParentid("0");
        Integer add = commentService.add(comment);
        return add;
    }

}
